package com.jsyl.lwbk.business.mq.receive;

/**
 * @author Fenny
 *
 */
//@Component
public class ScheduleChildReceiver {

//    private static final Logger logger = LoggerFactory.getLogger(ScheduleChildReceiver.class);
//
//    @Autowired
//    private CourseChildMapper courseChildMapper;
//    @Autowired
//    private ChildMapper childMapper;
//
//    @RabbitListener(queues = RabbitConfig.SCHEDULE_DETAIL_CHILD_OTO_MQ)
//    @RabbitHandler
//    public void saveScheduleDetailChild(@Payload String queue) {
//        logger.info("接收学生课程队列消息 ->", queue);
//        CourseChild scheduleChild = (CourseChild) JsonMapper.fromJsonString(queue, CourseChild.class);
//        JSONObject jasonObject = JSONObject.parseObject(queue);
//        Map map = (Map)jasonObject;
//        Long oldId = scheduleChild.getId();
//        Long childId = scheduleChild.getChildId();
//        String scheduleDetailId = String.valueOf(map.get("scheduleDetailId"));
//        Long scheduleId = Long.valueOf(scheduleDetailId);
//        scheduleChild.setCourseId(scheduleId);
//        scheduleChild.setConfirm(0);
//        CourseChildExample example =new CourseChildExample();
//        example.createCriteria().andChildIdEqualTo(childId).andCourseIdEqualTo(scheduleId).andStatusEqualTo(0);
//        CourseChild scheduleChildLocal = this.courseChildMapper.selectOneByExample(example);
//        //新增或更新(正常数据)
//        try {
//            if (map.containsKey("status") && (map.get("status").toString()).equals("2")){
//                if (scheduleChildLocal != null) {
//                    courseChildMapper.deleteByExample(example);
//                }
//            }else {
//                if (scheduleChildLocal != null){
//                    scheduleChild.setUpdateTime(new Date());
//                    scheduleChild.setId(scheduleChildLocal.getId());
//                    courseChildMapper.updateByExample(scheduleChild,example);
//                } else {
//                    Child childLocal = this.childMapper.selectById(oldId);
//                    scheduleChild.setChildName(childLocal!=null?childLocal.getName():"");
//                    scheduleChild.setCreateTime(new Date());
//                    scheduleChild.setUpdateTime(new Date());
//                    scheduleChild.setStatus(0);
//                    courseChildMapper.insert(scheduleChild);
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            logger.error("保存课程小孩关联表失败 ->{}", e.getMessage());
//            throw e;
//        }
//    }
}

